import axios from 'axios'

export default class Server {
  Api (methods, url, data = {}, header = {}) {
    let baseUrl = "http://devapi.ad6755.com"
    data.market_name = 'YaniangNoval'
    data.app_type = 34
    data.token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vdGVzdGFwaS5hZDY3NTUuY29tL3NhdmVfZGV2aWNlX2lkIiwiaWF0IjoxNTg1MTg5NDUyLCJleHAiOjE1ODUyNzU4NTIsIm5iZiI6MTU4NTE4OTQ1MiwianRpIjoiTWoyeUZGMDN0ak9mVDVjVyIsInN1YiI6MTA3NX0.D7ZQ3R0qKdLas9GxohDC9Et5q17KYyYY-V3Bu6NDQLg"
    header = Object.assign({
      'Content-Type': 'application/x-www-form-urlencoded',
      'version': '3.1.3',
      'appsystem': 'kuaiyingyong',
      'os': 0
    }, header)
    return new Promise((resolve, reject) => {
      axios({
        method: methods,
        url: baseUrl + url,
        header: header,
        responseType: 'json',
        data: data
      }).then(res => {
        resolve(typeof res.data === 'object' ? res.data : JSON.parse(res.data))

      }, error => {
        if (error.response) {
          reject(error.response.data)
        } else {
          reject(error)
        }
      })
    })
  }
}